Demo of Eddie, the Code Editor

by Alyce Watson [http://alycesrestaurant.com/]

NL133 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

Chat Challenge

Eddie Version 3

Stylebits Corner

Progress Bars

Velleman Interface

Sprite Byte

Simulating BMP Buttons

Program Security

LB Functions

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index




'** Eddie - an LB Code Editor
    'version 3
    'REQUIRES LIBERTY BASIC V 4.02 !!!
    'adds graphicbox for line numbers
    'changes font to be sized by pixels in texteditor
    'uses same font in graphicbox, so they line up
    'uses !origin? command in texteditor to get number of top visible row
    'adds timer to check origin of texteditor
    'if texteditor origin has changed, redraw line numbers in graphicbox
    'uses stylebits to remove border from graphicbox

[VariableSetup]
    '#f will be the handle for opening files
    'note that Version$ is a reserved variable name
    EddieVersion$ = "3"
    'path to Liberty.exe for running programs:
    LibertyExe$ = ""
    'name of ini file for this version of Eddie
    IniFile$ = "eddie3.ini"
    'variable to hold contents of texteditor
    text$ = ""
    'filename for writing a temp file to disk
    tempfile$ = DefaultDir$ + "\tempfile.bas"
    'filename for user saving file to disk
    savefile$ = ""

[WindowSetup]
    NOMAINWIN
    WindowWidth = 600 : WindowHeight = 360
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)

[ControlSetup]
'menus
Menu        #1, "&File", "&New", [new], "&Open", [open], "&Save", [save],_
            |,"&Print", [print], "E&xit", [quit]

'LB will place Edit menu where you specify in list of menus
'do not use ampersand & in Edit menu caption
Menu        #1, "Edit"
Menu        #1, "&Run","R&un", [run]
Menu        #1, "&Help", "He&lp", [help], "&About", [about]

'buttons for a toolbar lookalike
button      #1.new, "New",[new],UL, 0, 0, 45, 20
button      #1.open, "Open",[open],UL, 45, 0, 45, 20
button      #1.save, "Save",[save],UL, 90, 0, 45, 20
button      #1.print, "Print",[print],UL, 135, 0, 45, 20
button      #1.cut, "Cut",[cut],UL, 190, 0, 45, 20
button      #1.copy, "Copy",[copy],UL, 235, 0, 45, 20
button      #1.paste, "Paste",[paste],UL, 280, 0, 45, 20
button      #1.run, "Run",[run],UL, 335, 0, 45, 20
button      #1.help, "Help",[help],UL, 380, 0, 45, 20

'a graphicbox for line numbers
stylebits #1.g, 0,_WS_BORDER,0,0
graphicbox  #1.g, 0, 22, 39, 260
'a texteditor
texteditor  #1.te, 39, 22, 545, 280

Open "Eddie - an LB Code Editor v." + EddieVersion$ for Window as #1
    'trap the close event, if the user closes the
    'window with the X button
    #1 "trapclose [quit]"

    'set the font for the window and controls
    #1 "font ms_sans_serif 10"

    'set a custom font for the texteditor
    #1.te "!font courier_new 0 16"
    'set up the graphicbox
    #1.g "down; fill Buttonface; backcolor buttonface; flush"
    'use the same font as the texteditor
    #1.g "font courier_new 0 16"
    #1.g "autoresize"

    'cause the texteditor to resize automatically
    'when the user resizes the window
    #1.te "!autoresize"

    TIMER 50, [activateTimer]    'initialize the timer

[loop]
    Wait

[quit]
    TIMER 0
    close #1 : END

[activateTimer]
    'check the number of the row at the top of the texteditor
     #1.te "!origin? col row"
     'if it is the same as last check, do nothing
     if row = lastRow then wait
    'turn off timer for this routine
     TIMER 0
     'new lastRow is current row, for next check
     lastRow = row
     'delete previously named drawing segment called *linenums*
     #1.g "delsegment linenums"
     'location to start drawing line numbers
     #1.g "place 2 14"
     'fill with default buttonface color to erase previous line numbers
     #1.g "fill buttonface"
     'use top row number as starting number for line numbers
     for i = row to row+100
        'using() aligns the numbers for us
         num$=using("####",i)
         #1.g "\";num$
     next
     'flush and give this segment the name *linenums*
     #1.g "flush linenums"
     'start timer again
     TIMER 50, [activateTimer]
     wait

[new]
    #1.te "!CLS"
    Wait

[open]
    TIMER 0
    filedialog "Open","*.bas",openfile$
    if openfile$="" then wait

    open openfile$ for input as #f
    'dump contents of file into texteditor
    #1.te "!contents #f"
    close #f
    TIMER 50, [activateTimer]
    Wait

[save]
    TIMER 0
    'if the word SAVE is in the caption, LB
    'automatically creates a SAVE dialog
    filedialog "Save As","*.bas",savefile$
    if savefile$="" then wait

    'make sure that user had given the file a *bas extension
    if right$(lower$(savefile$),4)<>".bas" then
        savefile$=savefile$+".bas"
    end if

    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    if text$="" then
        notice "No file to save."
        wait
    end if

    'open file and write text to it
    open savefile$ for output as #f
        #f text$
    close #f
    TIMER 50, [activateTimer]
    Wait

[print]
    TIMER 0
    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    if text$="" then
        notice "No text to print."
        wait
    end if

    'send text to printer
    lprint text$
    'cause printing to happen now
    dump
    TIMER 50, [activateTimer]
    Wait

[help]
    'place code here
    Wait

[about]
    'place code here
    Wait

[cut]
    #1.te "!cut"
    wait

[copy]
    #1.te "!copy"
    wait

[paste]
    #1.te "!paste"
    wait

[run]
    TIMER 0
    'go to routine to get liberty.exe path
    'into variable LibertyExe$$
    gosub [GetLibertyPath]
    'if we can't find the path to Liberty BASIC
    'we must abort the RUN operation
    if LibertyExe$="" then wait

    'get contents of texteditor into string variable
    #1.te "!contents? text$"
    'if there is no code, then abort the RUN operation
    if text$="" then
        notice "No code to run."
        wait
    end if

    'open file and write text to it
    open tempfile$ for output as #f
        print #f, text$
    close #f

    'use RUN command to run Liberty BASIC
    'with this file loaded
    'put filename in quotation marks, so
    'that spaces do not break up the filename
    RUN LibertyExe$ + " " + chr$(34) + tempfile$ + chr$(34)
    TIMER 50, [activateTimer]
    wait

[GetLibertyPath]
    'file to store path info is IniFile$
    'open for append to see if file exists
    'attempting to open a nonexistent file for INPUT causes an error
    open IniFile$ for append as #f
    lenFile = LOF(#f)
    close #f

    'if the length = 0, the file doesn't exist
    if lenFile=0 then
        filedialog "Find Liberty.exe","*liberty*.exe",LibertyExe$
        if LibertyExe$="" then
            'the user cancelled the filedialog
            notice "Liberty.exe not found."
        else
            'the user selected liberty.exe on his computer
            'open the ini file and store the information
            open IniFile$ for output as #f
            print #f, LibertyExe$
            close #f
        end if
    else
        'if the length is greater than 0, the file exists
        'open it for input and read the first line
        'into the variable LibertyExe$
        open IniFile$ for input as #f
        line input #f, LibertyExe$
        close #f
    end if
    RETURN


NL133 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

Chat Challenge

Eddie Version 3

Stylebits Corner

Progress Bars

Velleman Interface

Sprite Byte

Simulating BMP Buttons

Program Security

LB Functions

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index